﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Candy
{
    public partial class ErrorWindow : ChildWindow
    {
        private Exception _exception;
        public Exception Exception
        {
            get
            {
                return _exception;
            }
            set
            {
                _exception = value;
                FormatText();
            }
        }

        private void FormatText()
        {
            errorTextBox.Text = "";
            if(_exception != null)
            {
                errorTextBox.Text += _exception.GetType().FullName + "\r\n";
                errorTextBox.Text += _exception.Message + "\r\n";
                errorTextBox.Text += _exception.StackTrace + "\r\n";

                if (_exception.InnerException != null)
                {
                    errorTextBox.Text = "++++++++++++++ INNER EXCEPTION +++++++++++++++++\r\n";
                    errorTextBox.Text += _exception.InnerException.GetType().FullName + "\r\n";
                    errorTextBox.Text += _exception.InnerException.Message + "\r\n";
                    errorTextBox.Text += _exception.InnerException.StackTrace + "\r\n";

                }
            }
        }


        public ErrorWindow()
        {
            InitializeComponent();
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
            Exception = null;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

